<template>
  <div class="login">
    <group title="">
	    <x-input title="手机号" required label-width="70px"  v-model="userName" :max="11" is-type="china-mobile" @on-change="verifyInfo()"></x-input>
			<x-input title="密码" required label-width="70px" min="6" max="16" type="password" placeholder="" v-model="password" :min="6" :max="6" @on-change="verifyInfo()"></x-input>
	  </group>
	  <div class="login_btn"><x-button type="primary" :disabled="verify" @click.native="login">登录</x-button></div>
  </div>
</template>

<script>

import { XInput,Group,XButton,Box  } from 'vux'
import axios from 'axios'


export default {
  name:"login",
  components: {
  	XInput,
  	Group,
  	XButton,
  	Box

  },
  data () {
    return {
    	userName:'',
    	password:'',
    	verify:true,
    	outtime:7,
    	loginUrl:'/login/login',
    	loginData:'',

    	login_secury:'',
    	mark:'1',


    }
  },
  methods: {
  	verifyInfo: function(){
  		var _this = this;
  		if(this.userName==''||this.password==''){
  			_this.verify=true;
  		}else{
  			_this.verify=false;
  		}
  	},
  	login: function(){
  		//this.outtime = Date.parse(new Date());
  		var data = {
  			account:this.userName,
  			password:this.password,
  			outtime:this.outtime,
  		}
  		var _this = this;
	    this.$http.post(  _this.loginUrl,data).then(function(res) {
	    	var res = res.data;
	        if (res.code == 200) {
	            _this.loginData = res.data;
	            _this.mark=res.data.mark;
	            _this.login_secury=res.data.login_secury;
	            //设置有效期15天
	            let expireDays = 1000 * 60 * 60 * 24 * 15;
  						_this.setCookie('token',_this.login_secury, expireDays);


	            _this.toastMsg("登录成功");
	            if(_this.mark==1){
	            	setTimeout(()=>{
	            			_this.$router.push({ path: "projectManager" });
	            	},1000);

	            	}else if(_this.mark==0){
	            		setTimeout(()=>{
	            			_this.$router.push({ path: "index" });
	            	},1000);

	            	}

	        } else {
	            _this.loginData = '';
	           // _this.toast("加载失败，请稍后再试");
	           _this.toastMsg(res.msg);
	          //console.log("请求失败")
	        }
	    })
	    .catch(function(err){
       // console.log(err);
    })
	    ;
	    //console.log("loginData"+this.loginData)
  	}
  },
}
</script>

<style scoped lang='less'>
	html,body{
		background-color: #fff !important;
		width: 100%;
		
	}
	.login{
		height: 100vh;
		background-color: #fff !important;
		padding-top: 110px;
		.login_btn{
			padding:23px 12px;
			background-color: #fff;
		}
	}

	.weui-cells:before {
    border-top: 0;
}
	.weui-cells:after {
	    border-top: 0;
	}




</style>
